#include "types.h"



int PD_Create_basic_datatype(MPI_Datatype type, int size_type){

size_elem_typev[typescount]=size_type;

tag_typev[typescount]=type;

typescount++;
return typescount-1;

}

int PD_Create_derived_datatype(int numtypes, int *blocklengths, MPI_Datatype * types, int size_type)
{

   	

    int i;
size_elem_typev[typescount]=size_type;
    MPI_Aint displacements[numtypes], extent;

    displacements[0] = (MPI_Aint) 0;
    for (i = 1; i < numtypes; i++) {
	MPI_Type_extent(types[i - 1], &extent);
	displacements[i] = displacements[i - 1] + extent;
    }

    MPI_Type_struct(numtypes, blocklengths, displacements, types, &tag_typev[typescount]);
    MPI_Type_commit(&tag_typev[typescount]);

	typescount++;
	return typescount-1;

}
int PD_Calculate_buffer_pack_size(int size, MPI_Datatype type)
{
    int k;
    MPI_Pack_size(size, type, MPI_COMM_WORLD, &k);
    return k;
}
int PD_Add_item_to_pack(char *buff, int buffsize, int *position, int size, void *content, MPI_Datatype type)
{

    MPI_Pack(content, size, type, buff, buffsize, position, MPI_COMM_WORLD);

   return 1;

}
int PD_Unpack_item_from_pack(char *buff, int buffsize, int *position, int size, void *content, MPI_Datatype type)
{


    MPI_Unpack(buff, buffsize, position, content, size, type, MPI_COMM_WORLD);

    return 1;	
}
